package com.chenshu.intercept_demo.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-04-21
 * Time：16:35
 */
@Component
@Aspect
public class LoginAspect {
//    @Pointcut("execution(* com.chenshu.intercept_demo.controller.validate.*.*(..))")
//    private void myPointcut(){};
//
//    @Around("myPointcut()")
//    public String loginValidate(ProceedingJoinPoint joinPoint) throws Throwable {
//        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
//        HttpSession session = request.getSession(false);
//        if (session == null) {
//            return "用户未登陆，请登录！！";
//        }
//        String username = (String) session.getAttribute("user");
//        if (username == null) {
//            return "用户未登陆，请登录！！";
//        }
//        return (String) joinPoint.proceed();
//    }
}
